<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/9/10
  Time: 16:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>首页展示</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script type="text/javascript" src="../js/jquery-1.12.4.js"></script>
    <script src="../layui/layui.js"></script>
    <script>
        //JavaScript代码区域
        layui.use('element', function(){
            var element = layui.element;
            //访问页面时发送ajax请求从后台获取导航栏的数据
            $.ajax({
                url:"${pageContext.request.contextPath}/menu/selectMenu",
                success:function (data) {
                    //遍历返回的数据 将对应的数据填充到页面
                    for (var i = 0;i < data.length; i++) {
                        console.info(data[i].menuName);
                        var liHtml = "";
                        liHtml = "<li class=\"layui-nav-item layui-nav-itemed\">\n" +
                            "                    <a class=\"\" href=\"javascript:;\">"+data[i].menuName+"</a>\n" +
                            "                    <dl class=\"layui-nav-child\" id='"+i+"'>\n" +
                            "                    </dl>\n" +
                            "                </li>"
                        $("#leftMenu").append(liHtml);
                        for (var j = 0; j < data[i].menus.length; j++) {
                            console.info(data[i].menus[j].menuName);
                            var ddHtml = "";
                            ddHtml = "<dd><a href=\"javascript:void(0);\" onclick='addTab(\"" +data[i].menus[j].menuName+"\","+data[i].menus[j].menuId+",\""+data[i].menus[j].menuUrl+"\")'>"+data[i].menus[j].menuName+"</a></dd>"
                            $("#"+i+"").append(ddHtml);
                        }
                        element.render('nav', 'leftNav');
                    }
                }
            })
        });
        function addTab(menuName,menuId,menuUrl) {
            var element = layui.element;
            element.tabAdd("myTab",{
                title: menuName
                ,content: '<iframe src=${pageContext.request.contextPath}'+menuUrl+' width="100%" height="100%"></iframe>' //支持传入html
                ,id: menuId
            })
            element.tabChange("myTab",menuId);
        }
    </script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">持明法洲</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a href="">控制台</a></li>
            <li class="layui-nav-item"><a href="">商品管理</a></li>
            <li class="layui-nav-item"><a href="">用户</a></li>
            <li class="layui-nav-item">
                <a href="javascript:;">其它系统</a>
                <dl class="layui-nav-child">
                    <dd><a href="">邮件管理</a></dd>
                    <dd><a href="">消息管理</a></dd>
                    <dd><a href="">授权管理</a></dd>
                </dl>
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                    贤心
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="">基本资料</a></dd>
                    <dd><a href="">安全设置</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="">退了</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree"  lay-filter="leftNav" id="leftMenu">

            </ul>
        </div>
    </div>

    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">
            <div class="layui-tab layui-tab-brief layui-tab-card" lay-allowClose="true" lay-filter="myTab">
                <ul class="layui-tab-title">
                </ul>
                <div class="layui-tab-content">
                </div>
            </div>
        </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © layui.com - 底部固定区域
    </div>
</div>

</body>
</html>
